﻿angular.module("app").factory('upgradeData', function() {

  var accessories = [];

  var longSwords = [];
  var lightBlades = [];
  var maces = [];
  var staves = [];
  var axes = [];
  var weapons = [longSwords, lightBlades, maces, staves, axes];

  var armors = [];
  var chests = [];
  var heads = [];
  var opens = [];
  var legs = [];
  var protections = [armors, chests, heads, opens, legs];

  var upgrades = [weapons, protections, accessories];

  function upgrade(name, type, use, attack, defense, agility, resist, unleash, cost) {
    this.name = name;
    this.attack = attack;
    this.defense = defense;
    this.agility = agility;
    this.resist = resist; //[0,0,0,0];
    this.type = type;
    this.use = use; //[0, 0, 0, 0, 0, 0, 0, 0];
    this.unleash = unleash; //function (){};
    this.cost = cost;
    pushUpgrade(this);
  };

  function weapon(name, type, use, attack, unleash, cost) {
    return upgrade(name, type, use, attack, 0, 0, 0, unleash, cost);
  }

  function armor(name, type, use, defense, agility, resist, unleash, cost) {
    return upgrade(name, type, use, 0, defense, agility, resist, unleash, cost);
  }

  function accessory(name, unleash, cost) {
    return upgrade(name, "accessory", [1, 1, 1, 1, 1, 1, 1, 1], 0, 0, 0, 0, unleash, cost);
  }

  function pushUpgrade(upg) {
    switch (upg.type) {
    case 'longSword':
      longSwords.push(upg);
    case 'mace':
      maces.push(upg);
    case 'lightBlade':
      lightBlades.push(upg);
    case 'staff':
      staves.push(upg);
    case 'axe':
      axes.push(upg);
    case 'armor':
      armors.push(upg);
    case 'chest':
      chests.push(upg);
    case 'head':
      heads.push(upg);
    case 'open':
      opens.push(upg);
    case 'legs':
      legs.push(upg);
    case 'accessory':
      accessories.push(upg);
    default:
    }
  }

  var eu = function() {};
  var woodenStick = weapon("Wooden Stick", "staff", [0, 0, 1, 0, 0, 0, 1, 1], eu, 40);

  return {
    getAll: function() {
      return upgrades;
    }
  };
});